<?php

require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'AtomController.php';

class PagesController extends AtomController 
{
	
	//public function display()
	public function indexAction()
	{
//		$this->errorNotFound();
		/*
		$uri = $this->getRequest()->getServer('HTTP_HOST') . $this->getRequest()->getRequestUri();
		$pages = new Pages();
		$page = $pages->fetchRow($pages->select()->where('uri = ?', $uri));
		$this->view->page = $page;
		
		if (!$page)
			throw new Zend_Controller_Dispatcher_Exception('Cannot find Page');
		
		$this->view->setScriptPath(dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'templates');
		$this->renderScript('display.phtml');*/
	}
	
	
	public function collection()
	{
		$pages = new Pages();
		$select = $pages->select()->setIntegrityCheck(false);
		$select->from($pages, "*")
				->joinLeft('users', 'users.id = pages.user_id', 'CONCAT(firstName, " ", lastName) AS author')
				->order("lft");
		$pages = $pages->fetchAll($select);
		
		if (!count($pages))
			$this->errorNotFound();
		
		$this->view->pages = $pages;
	}
	
	public function view($key)
	{
		$pages = new Pages();
		$page = $pages->fetchRow($pages->select()->where("location = ?", $key));
		
		if (!$page)
			$this->errorNotFound();
		
		$this->view->page = $page;
	}
	
	public function create()
	{
		
	}
	
	public function update($key)
	{
		var_dump($this->data);
		exit;
	}
	
	public function delete($key)
	{
		
	}

	/**
	 * Return the Request object
	 *
	 * @return Zend_Controller_Request_Http
	 */
	public function getRequest()
	{
		return $this->_request;
	}

	public function display()
	{
		
	}

}